package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ArticleController {


    @Autowired
    private IArticleService articleService;

    @RequestMapping("/articles")
    public String pageQuery(Model model,
                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
                            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        Page<Article> articles = articleService.pageQuery(pageNum, pageSize);
        model.addAttribute("articles", articles);
        return "index";
    }

    @RequestMapping("/index")
    public String index() {
        return "redirect:/articles";
    }
}
